import QtQuick
import QtQuick.Controls
import QtQuick.Window
import QtQuick.Dialogs
import waycpp 1.0
Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Image Viewer")

    Myclass {
            id: pathreturn
            onDataReceived:{
                imageview.source=""
                imageview.source = "file://"+lpathss

            }
    }

    BusyIndicator {
        id: loading
        running: false
        anchors.centerIn: parent
        z: 2
    }

    FileDialog {
        id: fileDialog
        title: qsTr("Select Image File")
        nameFilters: ["Image Files (*.jpg *.jpeg *.png *.bmp *.gif)"]
        onAccepted: {
            pathreturn.CopyAndgetRealPath(selectedFile.toString());
            console.log("content路径:", currentFile.toString());
              console.log("真实路径:",imageview.source);
        z: 1
        }

}

    SplitView {
            anchors.fill:  parent
            orientation: Qt.Vertical
            MenuBar {
                   Menu {
                       title: "文件"


                       MenuItem { text: "打开"; onClicked: fileDialog.open()}
                       MenuItem { text: "保存"; onClicked: saveDialog.open() }
                       MenuSeparator {}
                       MenuItem { text: "退出"; onTriggered: Qt.quit()  }
                   }
                      Menu {
                     width: 200
                        }
                   Menu {
                       title: "退出"
                       MenuItem { text: "复制" }
                       MenuItem { text: "粘贴" }
                   }
                   Menu {
                       title: "步骤"
                       MenuItem { text: "上一步" }
                       MenuItem { text: "下一步" }
                   }
                   Menu {
                       title: "步骤"
                       MenuItem { text: "上一步" }
                       MenuItem { text: "下一步" }
                   }
               }


            handle: Rectangle {
                   implicitHeight: 15 // 垂直方向手柄高度
                   color: SplitHandle.pressed ? "blue" : "black"
               }

            Rectangle {
                id:show
                SplitView.fillHeight:  true
                SplitView.minimumHeight:  50
                Drawer {
                    id: drawerduibi
                    width: 0.3 * show.width   // 抽屉宽度占父容器30%
                    height: show.height
                    edge: Qt.LeftEdge          // 从左侧滑出

                    Slider {
                        id: slider2
                        width: 30
                        height:600
                        orientation:Qt.Vertical
                        from: 0
                        to: 100
                        value: 50
                         onValueChanged:
                         {pathreturn.getsliderturn(value)
                         pathreturn.requestOpencv(fileDialog.currentFile.toString(),3)

                         }
                    }
                }
                Image {
                    id: imageview
                    anchors.fill: show
                    width:500
                    height: 500
                    fillMode: Image.PreserveAspectFit
                    asynchronous: true
                    cache: false

                     onProgressChanged: console.log("Loading  progress:", progress)

                    onStatusChanged: {
                        console.log("Image  status:", status)
                        switch(status) {
                        case Image.Loading:
                            loading.running = true;
                            lblStatus.visible = false;
                            break;
                        case Image.Ready:
                            loading.running = false;
                            lblStatus.visible = false;
                            break;
                        case Image.Error:
                            loading.running = false;
                            lblStatus.text = qsTr("Load Failed");
                            lblStatus.visible = true;
                            break;
                        }
                    }

                    z: 1
                }
            }  // 照片显示区
                Rectangle
                {
                    id:dosome
                    SplitView.preferredHeight:  100
                    SplitView.minimumHeight:  100
                    color: "gray"

               Flow{
                      spacing: 7
                       flow: Flow.LeftToRight
                      width: parent.width
                      Rectangle{
                          width: 121
                          height: 41
                          color: "#2196F3"
                          border.color: "#1976D2"
                          border.width: 1
                  Button {
                      id: btnlight
                      text: qsTr("亮度")
                      width: 120
                      height: 40

                      background: Rectangle {
                          color: "#2196F3"
                      }

                       onClicked: {
                           pathreturn.requestOpencv(fileDialog.currentFile.toString(),3);
                            console.log("真实路径:",imageview.source);

                  }
                       z: 1
                  }
                      }
                      Rectangle{
                          width: 121
                          height: 41
                          color: "#2196F3"
                          border.color: "#1976D2"
                          border.width: 1
                  Button {
                      id: btnduibi
                      text: qsTr("对比度")
                      width: 120
                      height: 40

                      background: Rectangle {
                          color: "#2196F3"
                      }

                       onClicked: {

                          pathreturn.requestOpencv(fileDialog.currentFile.toString(),3);
                           console.log("真实路径:",imageview.source);

                  }
                       z: 1
                  }
                      }
                        Rectangle{
                            width: 121
                            height: 41
                            color: "#2196F3"
                            border.color: "#1976D2"
                            border.width: 1
                    Button {
                        id: btnone1
                        text: qsTr("一键美图")
                        width: 120
                        height: 40

                        background: Rectangle {
                            color: "#2196F3"
                        }

                         onClicked: {

                            pathreturn.requestOpencv(fileDialog.currentFile.toString(),1);
                             console.log("真实路径:",imageview.source);

                    }
                         z: 1
                    }
                        }

                Rectangle{
                    width: 271
                    height: 40
                    color: "#2196F3"
                    border.color: "#1976D2"
                    border.width: 1

                }
                Rectangle{
                                width: 151
                                height: 41
                                color: "#2196F3"
                                border.color: "#1976D2"
                                border.width: 1
                       Button {
                           id: btntwo2
                           text: qsTr("换证件照背景")

                           width: 150
                           height: 40

                           background: Rectangle {
                               color: "#2196F3"
                           }

                            onClicked: {
                              pathreturn.requestOpencv(fileDialog.currentFile.toString(),2);

                               console.log("真实路径:",imageview.source);

                            }
                             z: 1
                       }
                    }
                    Label
                    {
                        id: lblStatus

                        visible: false  // 根据数据模型状态切换显示
                        font.pixelSize: 24
                        color: "red"
                        z: 1
                    }
                }  // 美图功能区
        }
            }



}

